package com.symbio.ishenapi.background.controller;

import com.symbio.ishenapi.background.model.TmBanner;
import com.symbio.ishenapi.common.controller.BaseController;
import io.jboot.web.controller.annotation.RequestMapping;

import java.util.Date;

/**
 * @Author: chen
 * @Description:广告素材管理控制层
 * @Date: Created in 11:19 2018/10/22
 * @Modified By:
 */

@RequestMapping("/TmBanner")
public class TmBannerController extends BaseController {

    /**
     * 广告素材列表展示查询
     */
    public void findList(){

        String type = getPara("type");
        renderJsonRet(TmBanner.dao.findList(type));
    }

    /**
     * 广告素材添加
     */
    public void save(){
        TmBanner tmBanner = (TmBanner)getReqBodyObject(TmBanner.class);
        //填充数据
        tmBanner.setRevJson("{}");
        //获取登录人信息(待补充)
        tmBanner.setCreateBy("admin");
        tmBanner.setCreateTime(new Date());
        tmBanner.setUpdateBy("admin");
        tmBanner.setUpdateTime(new Date());
        //默认素材禁用，数据有效
        tmBanner.setEnable(0);
        tmBanner.setStatus(1);

        if(tmBanner.getContent()==null||"".equals(tmBanner.getContent())){
            renderJsonError(40003, "素材内容");
        }
        if(tmBanner.getType()==null){
            renderJsonError(40003, "素材类型");
        }

        if (tmBanner.save())
            renderJsonRet(40001);
        else
            renderJsonError(40002);
    }

    /**
     * 广告素材逻辑删
     */
    public void delete(){
        TmBanner tmBanner = (TmBanner)getReqBodyObject(TmBanner.class);
        if(TmBanner.dao.deleteBanner(tmBanner) > 0) {
            renderJsonRet(40004);
        }else{
            renderJsonError(40005);
        }
    }

    /**
     * 是否启用素材
     */
    public void upEnable(){
        TmBanner tmBanner = (TmBanner)getReqBodyObject(TmBanner.class);
        //获取登录人信息
        tmBanner.setUpdateBy("admin");
        tmBanner.setUpdateTime(new Date());

        if(TmBanner.dao.upEnable(tmBanner) > 0){
            renderJsonRet(40004);
        }else{
            renderJsonError(40005);
        }
    }
}
